<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="所属区县" prop="orgCode">
        <el-cascader v-model="orgCodeList" @change="orgCodeChange" :options="options" :show-all-levels="false" :props="{ checkStrictly: true,value: 'code',label: 'name',children: 'chridrenList' }" clearable></el-cascader>
      </el-form-item>
      <el-form-item label="维护站名称" prop="wxUnit">
        <el-select v-model="queryParams.wxUnit" filterable clearable placeholder="请选择维护站名称">
          <el-option
            v-for="item in wxUnitList"
            :key="item"
            :label="item"
            :value="item">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="维护站编号" prop="wxCode">
        <el-input
          v-model="queryParams.wxCode"
          placeholder="请输入维护站编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table  border v-loading="loading" :data="secondaryList">
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="维护站编号" align="center" prop="wxCode" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="维护站名称" align="center" prop="wxUnit" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="企业类型" align="center" prop="enterpriseType" >
        <template slot-scope="scope">
          <span v-if="scope.row.enterpriseType === 1">维修企业</span>
          <span v-if="scope.row.enterpriseType === 2">营运车辆企业</span>
          <span v-if="scope.row.enterpriseType === 3">综合性能企业</span>
        </template>
      </el-table-column>
      <el-table-column label="维护站地址" align="center" prop="wxAddr" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="工位数" align="center" prop="workstation" />
      <el-table-column label="联系人" align="center" prop="wxPerson" />
      <el-table-column label="联系电话" align="center" prop="wxTel" />
      <el-table-column label="统一社会信用编码" width="130" align="center" prop="creditCode" />
      <el-table-column label="营业执照照片" align="center" prop="licensepic" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.licensepic"></image-preview>
        </template>
      </el-table-column>
      <el-table-column label="计量证书照片" align="center" prop="measurementTestingCertificate" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.measurementTestingCertificate"></image-preview>
        </template>
      </el-table-column>
      <el-table-column label="法人" align="center" prop="legalPerson" />
      <el-table-column label="法人电话" align="center" prop="legalTel" width="120"/>
      <el-table-column label="经营范围" align="center" prop="businessScope" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="区划编码" align="center" prop="orgCode" />
      <el-table-column label="所属区县" align="center" prop="orgName" width="180"/>
      <el-table-column label="站点状态" align="center" prop="status" >
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.status === 0">禁用</el-tag>
          <el-tag type="success" v-if="scope.row.status === 1">启用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否审核" align="center" prop="isApproval" >
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.isApproval === '0'">未审核</el-tag>
          <el-tag type="success" v-if="scope.row.isApproval === '1'">已审核</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审核结果" align="center" prop="approvalResult">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.approvalResult === '0'">同意</el-tag>
          <el-tag type="danger" v-if="scope.row.approvalResult === '1'">不同意</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审核意见" align="center" prop="approvalComments" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="禁用原因" align="center" prop="prohibitReason" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" width="180" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-finished"
            @click="handleView(scope.row)"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      title="审核意见"
      :visible.sync="examineOpen"
      width="30%">
      <el-form ref="form" :model="examineParam" label-width="80px">
        <el-form-item label="审核意见" required>
          <el-input type="textarea" v-model="examineParam.approvalComments"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="submitExamine">确 定</el-button>
  </span>
    </el-dialog>
    <el-dialog
      :visible.sync="openSiteData"
      width="50%">
      <el-descriptions class="margin-top"  title="站点信息" :column="1" border>
        <template slot="extra">
          <el-button-group>
            <el-button type="primary" @click="handleApproved(toExamineList.id)">审核通过</el-button>
            <el-button type="danger" @click="reviewNotApproved(toExamineList.id)">审核不通过</el-button>
          </el-button-group>
        </template>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            维护站编码
          </template>
          {{toExamineList.wxCode}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            维护站名称
          </template>
          {{toExamineList.wxUnit}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            维护站地址
          </template>
          {{toExamineList.wxAddr}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            联系人
          </template>
          {{toExamineList.wxPerson}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            联系电话
          </template>
          {{toExamineList.wxTel}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            所属区县
          </template>
          {{toExamineList.orgName}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            企业类型
          </template>
          {{toExamineList.enterpriseType}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            统一社会信用编码
          </template>
          {{toExamineList.creditCode}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            营业执照照片
          </template>
          <image-preview :src="toExamineList.licensepic" :width="50" :height="50"></image-preview>
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            法人
          </template>
          {{toExamineList.legalPerson}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            法人电话
          </template>
          {{toExamineList.legalTel}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            工位数
          </template>
          {{toExamineList.workstation}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            经营范围
          </template>
          {{toExamineList.businessScope}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            站点状态
          </template>
          {{toExamineList.status === 0 ? '禁用' : '启用'}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            禁用原因
          </template>
          {{toExamineList.prohibitReason}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            审核状态
          </template>
          {{toExamineList.isApproval === '0' ? '未审核' : '已审核'}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            审核结果
          </template>
          {{toExamineList.approvalResult === '0' ? '同意' : '不同意'}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            审核意见
          </template>
          {{toExamineList.approvalComments}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            编辑状态
          </template>
          {{toExamineList.isEdit === '0' ? '可编辑' : '不可编辑'}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            计量证书照片
          </template>
          <image-preview :src="toExamineList.measurementTestingCertificate" :width="50" :height="50"></image-preview>
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            计量证书开始日期
          </template>
          {{toExamineList.certificateStartDate}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            计量证书结束日期
          </template>
          {{toExamineList.certificateEndDate}}
        </el-descriptions-item>
        <el-descriptions-item :labelStyle="{'font-weight':'bold'}">
          <template slot="label">
            证书有效期(天)
          </template>
          {{toExamineList.certificatePeriodValidity}}
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
import { toExamineList, toExamineApproved } from '@/api/maintenanceenterprise/toexamine';
import { getSecondary,siteNameList} from '@/api/maintenanceenterprise/secondarysite';
import { getDistrictTreeList } from "@/api/system/district";
import { getToken } from "@/utils/auth";
import {toExamineNotApproved} from "../../../api/maintenanceenterprise/toexamine";
export default {
  name: "Secondary",
  data() {
    return {
      orgCodeList: [],
      examineOpen: false,
      openSiteData: false,
      wxUnitList: [],
      toExamineList: {},
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      props: {
        label: "name",
        value: "code",
        children: "chridrenList"
      },
      options: [],
      openImportData: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 汽车检测-二级维护站表格数据
      secondaryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        wxCode: null,
        wxUnit: "",
        wxAddr: null,
        wxPerson: null,
        wxTel: null,
        creditCode: null,
        legalPerson: null,
        legalTel: null,
        orgCode: null,
        enterpriseType: null
      },
      // 表单参数
      form: {},
      examineParam: {},
    };
  },
  created() {
    this.getList();
    this.getDistrictTreeList();
    this.getSiteNameList();
  },
  methods: {
    getDistrictTreeList(){
      getDistrictTreeList().then(res => {
        this.options = res.data
      })
    },
    getSiteNameList() {
      this.queryParams.orgCode = this.orgCodeList[this.orgCodeList.length - 1];
      siteNameList(this.queryParams).then(res => {
        this.wxUnitList = res.data;
      })
    },
    orgCodeChange(){
      this.queryParams.orgCode = this.orgCodeList[this.orgCodeList.length - 1];
      siteNameList(this.queryParams).then(res => {
        this.wxUnitList = res.data;
      })
    },
    submitExamine(){
      toExamineNotApproved(this.examineParam).then(response => {
        this.$message.success("站点审核完成")
        this.getList()
        this.examineOpen = false;
        this.openSiteData = false;
      })
    },
    reviewNotApproved(id){
      this.examineParam.vehicleSiteId = id;
      this.examineOpen = true;
    },
    handleApproved(id){
      this.examineParam.vehicleSiteId = id;
      toExamineApproved(this.examineParam).then(response => {
        this.$message.success("站点审核通过")
        this.getList()
        this.openSiteData = false;
      })
    },
    handleView(row){
      getSecondary(row.id).then(res => {
        this.toExamineList = res.data;
        this.openSiteData = true;
      })
    },
    /** 查询汽车检测-二级维护站列表 */
    getList() {
      this.loading = true;
      this.queryParams.orgCode = this.orgCodeList[this.orgCodeList.length - 1];
      toExamineList(this.queryParams).then(response => {
        this.secondaryList = response.records;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        wxCode: null,
        wxUnit: null,
        wxAddr: null,
        wxPerson: null,
        wxTel: null,
        creditCode: null,
        licensepic: null,
        legalPerson: null,
        legalTel: null,
        businessScope: null,
        orgCode: null,
        createTime: null,
        updateTime: null,
        measurementTestingCertificate: null,
        workstation: null,
        certificateStartDate: null,
        certificateEndDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.orgCode) {
        this.queryParams.orgCode = this.queryParams.orgCode[this.queryParams.orgCode.length - 1];
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.orgCodeList = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
